// 1.设置标识
const KEY = 'vue_xyAdmin_token_2006'
// 2.设置value
const USER_KEY = 'user_info_2006'

// 设置token
export function setToken(value) {
  localStorage.setItem(KEY, value)
}
// 获取tOKEN
export function getToken() {
  var tokenStr = window.localStorage.getItem(KEY)
  if (!tokenStr || tokenStr === 'undefined') {
    return null
  } else {
    return tokenStr
  }
}
// 删除Token
export function removeToken() {
  window.localStorage.removeItem(KEY)
}

// 保存用户信息
export function saveUserInfo(userInfo) {
  if (userInfo) {
    var userInfoStr = JSON.stringify(userInfo)
    window.localStorage.setItem(USER_KEY, userInfoStr)
  }
}

export function getUserInfo() {
  var userInfoStr = window.localStorage.getItem(USER_KEY)
  if (!userInfoStr || userInfoStr == '') {
    return null
  } else {
    var userInfo = JSON.parse(userInfoStr)
    return userInfo
  }
}

export function removeUserInfo() {
  window.localStorage.removeItem(USER_KEY)
}

// 清空所有用户缓存
export function clearUserCache() {
  removeToken()
  removeUserInfo()
}
